package com.cy.ppj.web.admin.product;

import com.cy.ppj.model.PageBean;
import com.cy.ppj.model.Result;
import com.cy.ppj.model.ao.product.TagAddAO;
import com.cy.ppj.model.ao.product.TagEditAO;
import com.cy.ppj.model.query.TagAdminQuery;
import com.cy.ppj.model.domian.product.Tag;
import com.cy.ppj.model.enums.TagStatus;
import com.cy.ppj.service.product.ProductService;
import com.cy.ppj.service.product.TagService;
import com.cy.ppj.web.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @description: 标签管理
 * @author: Ocean
 * @create: 2018-07-17 18:49
 **/
@Slf4j
@RestController
@RequestMapping("/admin/product/tag")
@Api(tags = "后台-产品标签管理")
public class AdminProductTagController extends BaseController {

    @Autowired
    private TagService tagService;
    @Autowired
    private ProductService productService;

    @ApiOperation("添加产品标签")
    @PostMapping("/add")
    public Result add(@Validated TagAddAO tagAddAO, BindingResult bindingResult) {
    	this.checkError(bindingResult);
        tagService.addTag(tagAddAO);
        return ok();
    }

    @ApiOperation("标签列表")
    @GetMapping("/list")
    public PageBean<Tag> list(TagAdminQuery tagAdminQuery) {
        return tagService.adminTags(tagAdminQuery);
    }

    @ApiOperation("编辑标签")
    @PostMapping("/update")
    public Result update(@Validated TagEditAO tagEditAO, BindingResult bindingResult) {
    	this.checkError(bindingResult);
        tagService.updateTag(tagEditAO);
        return ok();
    }

    @ApiOperation("更新标签状态")
    @PostMapping("/update/status")
    public Result updateStatus(@ApiParam(value = "标签id", example = "0", required = true) @RequestParam Long tagId,
    		@ApiParam(value = "状态", required = true) @RequestParam TagStatus tagStatus) {
    	tagService.updateTagStatus(tagId, tagStatus);
    	return ok();
    }
    
    @ApiOperation("标签详情信息")
    @GetMapping("/detail")
    public Result Detail(@ApiParam(value = "标签id", example = "0", required = true) @RequestParam Long tagId) {
    	return ok("查询成功", tagService.selectTagDetailAdmin(tagId));
    }
    
    @ApiOperation("全部标签列表")
    @GetMapping("/all/tags")
    public Result allTags() {
    	return ok("查询成功", tagService.allTagsInCache());
    }
    
    @ApiOperation("全部产品类型列表")
    @GetMapping("/all/types")
    public Result allTypesInCache() {
    	return ok("查询成功", productService.allTypesInCache());
    }
}
